﻿using MediatR;
using TaskProject.Application.Command.BOM;
using TaskProject.Domain.BOM;
using TaskProject.ErrorCode;
using TaskProject.InfrasIntructure.Interface;

namespace TaskProject.Application.Handler.BOM
{
    public class GetCraftHandler : IRequestHandler<GetCraftCommand, APIResult<List<CraftModel>>>
    {
        IBaseRepository<CraftModel> craftRepo;

        public GetCraftHandler(IBaseRepository<CraftModel> craftRepo)
        {
            this.craftRepo = craftRepo;
        }

        public Task<APIResult<List<CraftModel>>> Handle(GetCraftCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<CraftModel>> res = new APIResult<List<CraftModel>>();
            var crafts=craftRepo.GetAll().Where(c=>c.ProductId==request.ProductId).ToList();
            res.Msg = "查询工艺表成功";
            res.Code = APIEnum.Success;
            res.Data = crafts;
            return Task.FromResult(res);
        }
    }
}
